import json

from flask import Flask, render_template, Response
from werkzeug.routing import BaseConverter

app = Flask(__name__)


#自定义转换器
class PhoneConverter(BaseConverter):
    regex = r'1[34578]\d{9}'

app.url_map.converters['phone'] = PhoneConverter

@app.route('/phone/<phone:phone>')
def phone(phone):
    return f'phone: {phone}'


# # 方式一
# app.config['SECRET_KEY'] = '123@qwee'
# app.config['SQLALCHEMY_DATABASE_URI'] = ''
# app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
#
# # 方式二
# app.config.update(
#     MAIL_SERVER='smtp.qq.com',
#     MAIL_PORT=465,
#     MAIL_USE_SSL=True,
#     MAIL_USERNAME='',
#     MAIL_PASSWORD='',
#     MAIL_DEFAULT_SENDER=''
# )
#
# # 方式三
# app.config.from_file('config.json', load=json.load())


@app.route('/hello1/<num>', methods=['GET'])
def hello_world(num):  # put application's code here
    return 'Hello World!' + num


@app.route('/index_resp')
def index_resp():
    # 使用Response类的构造方法生成响应对象，设置状态码为201，响应类型为text/html
    resp = Response(response='Python&Flask', status=201,
                        content_type='text/html;charset=utf-8')
    return resp


@app.route('/index')
def index():
    name = 'hello'
    return render_template('index.html', name=name)  # 渲染模板文件index.html


@app.route('/user/list')
def user_index():
    name = 'hello'
    return render_template('index.html', name=name)  # 渲染模板文件index.html


@app.route('/dept/list')
def dept_index():
    name = 'hello'
    return render_template('index.html', name=name)  # 渲染模板文件index.html


if __name__ == '__main__':
    app.run()
